package cn.zktr.Personnel.controllers.ouyangpeng;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.zktr.Personnel.model.pojos.PerPmsEmp;
import cn.zktr.Personnel.model.pojos.PerRetIrw;
import cn.zktr.Personnel.model.pojos.PerRetRcd;
import cn.zktr.Personnel.model.pojos.PerRetRse;
import cn.zktr.Personnel.model.pojos.PerRetWen;
import cn.zktr.Personnel.model.service.ouyangpeng.RetIrwService;
import cn.zktr.Personnel.model.service.ouyangpeng.RetIttService;
import cn.zktr.Personnel.model.service.ouyangpeng.RetRseService;
import cn.zktr.Personnel.model.service.ouyangpeng.RetWAltService;
import cn.zktr.Personnel.model.service.ouyangpeng.RetWenService;

@Controller

public class RetceshiController {
	@Autowired
	private RetWAltService retwalt;
	@Autowired
	private RetRseService retrse;
	@Autowired
	private RetIttService retittservice;
	@Autowired
	private RetIrwService retirwservice;
	@Autowired
	private RetRseService retrseservice;
	@Autowired
	private RetWenService retwenservice;
	//考试详情
	@RequestMapping("oyp/recruit-kaoshi")
	public void demo9(Model model) {
		recruit(model);
	}
	
//	@RequestMapping("mianshi_reesidss")
//	@ResponseBody
//	private void mianshi_rseidsdef(Model model,int mianshiidrseid) {
//		model.addAttribute("main_shi_rseidsep", retittservice.selectmianshirseidss(mianshiidrseid));
//	}
	//笔试记录表
    @RequestMapping("bishi_jilushouye")
    @ResponseBody
    public Map<String,Object> bishibiao(int page,int rows){
	    Map<String,Object> map = new HashMap<>();
	    map.put("total",retittservice.bishi_cx().size());
	    Page<Object> p=PageHelper.startPage(page,rows);
	    List<PerRetWen> findAll=retittservice.bishi_cx();
	    //页内容
	    map.put("rows",findAll);
	    return map;
    }
    //笔试通过
    @PostMapping("bishi_tongguole")
    @ResponseBody
    private void bishiwen(HttpSession session,int bishitongguo_id) {
    	session.setAttribute("wenid", retittservice.updatebishiid(bishitongguo_id));
    	retittservice.wenxiugai(bishitongguo_id);
    }
    //笔试不通过
    @PostMapping("bishi_meitongguole")
    @ResponseBody
    private void bishibuwen(HttpSession session,int bishibutongguo_id) {
    	session.setAttribute("wenid", retittservice.updatebishiid(bishibutongguo_id));
    	retittservice.wenbutg(bishibutongguo_id);
    }
	//面试记录表
	@RequestMapping("mianshi_jilu")
    @ResponseBody
    public Map<String,Object> mianshibiao(int page,int rows){
		Map<String,Object> map = new HashMap<>();
		map.put("total",retirwservice.selectirw().size());
		Page<Object> p=PageHelper.startPage(page,rows);
		List<PerRetIrw> findAll=retirwservice.selectirw();
		//页内容
		map.put("rows",findAll);
		return map;
    }
	//添加面试记录时获取简历id
	@RequestMapping("bishirseidwenid")
	@ResponseBody
	public List<PerRetWen> bissrse() {
		return retittservice.selectksrseid();
	}
	@RequestMapping("bishi_jianliid")
	@ResponseBody
	private void mianshiiddss(HttpSession session,Integer kaoshi_rseid) {
		session.setAttribute("bishirseid", retrseservice.selectrseid(kaoshi_rseid));
	}
	//新增面试记录
	@PostMapping("xz_mianshi")
	@ResponseBody
	public void zxminashi(int msren,int msguan,String msbeizhu) {
		PerRetRse rse=new PerRetRse();//面试人
		rse.setRseid(msren);
		PerPmsEmp emp=new PerPmsEmp();//面试官
		emp.setEmpid(msguan);
		
		PerRetIrw irw=new PerRetIrw();
		irw.setPerRetRse(rse);
		irw.setPerPmsEmp(emp);
		irw.setIrwrem(msbeizhu);
		retirwservice.mainshixz(irw);
		//retwenservice.selectwenjiehsu(bishi_wenid);//修改状态
	}
	//修改面试状态
	 @PostMapping("mianshi_tongguo")
	 @ResponseBody
	 private void irw_hge(Integer mianshi_irw,Integer mianshi_wen) {
		 retirwservice.irwhege(mianshi_irw);
		 retwenservice.selectwenjiehsu(mianshi_wen);
	 }
    //面试合格则添加最终审核
	@PostMapping("shenhe_zuizhong")
	@ResponseBody
	public void zzshenhe(int mianshi_irw,int mianshi_wen,int mianshi_rse) {
		PerRetRse rse=new PerRetRse();//简历id
		rse.setRseid(mianshi_rse);
		PerRetWen wen=new PerRetWen();//笔试id
		wen.setWenid(mianshi_wen);
		PerRetIrw irw=new PerRetIrw();
		irw.setIrwid(mianshi_irw);
		
		PerRetRcd rcd=new PerRetRcd();
		rcd.setPerRetRse(rse);
		rcd.setPerRetWen(wen);
		rcd.setPerRetIrw(irw);
		retirwservice.zzshenhe(rcd);
	}
	public void recruit(Model model) {
			model.addAttribute("deptname", retwalt.selectDept());                 //部门
			model.addAttribute("empname", retwalt.selectemp());		              //员工
			model.addAttribute("potname", retwalt.selectpot());                   //职位
			model.addAttribute("potnames", retrse.selectyuangong());              //职级-职位列表
			model.addAttribute("yiyoupot", retrse.selectyiyouzy());               //已进行计划的职位
			model.addAttribute("fuzerennames", retrse.selectfuzenren());          //负责人
			model.addAttribute("jnxxname", retwalt.selectjineng());               //技能
			model.addAttribute("sexname", retrse.selectsex());                    //性别
			model.addAttribute("jihuanames", retrse.selectjihua());               //招聘计划
			model.addAttribute("xueliname", retrse.selectxueli());                //学历
			model.addAttribute("rsename", retrse.selerseAll());    				  //应聘人员
			//model.addAttribute("ksrse", retittservice.selectksrseid());    		  //添加面试时通过笔试的简历
	}
}
